// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.worldMap;

import java.util.ArrayList;
import java.util.HashMap;
import zombie.characters.IsoPlayer;

public final class WorldMapRemotePlayers {
    public static final WorldMapRemotePlayers instance = new WorldMapRemotePlayers();
    private final ArrayList<WorldMapRemotePlayer> playerList = new ArrayList();
    private final HashMap<Short, WorldMapRemotePlayer> playerLookup = new HashMap();

    public WorldMapRemotePlayer getOrCreatePlayerByID(short _short) {
        WorldMapRemotePlayer worldMapRemotePlayer = (WorldMapRemotePlayer)this.playerLookup.get(_short);
        if (worldMapRemotePlayer == null) {
            worldMapRemotePlayer = new WorldMapRemotePlayer(_short);
            this.playerList.add(worldMapRemotePlayer);
            this.playerLookup.put(_short, worldMapRemotePlayer);
        }

        return worldMapRemotePlayer;
    }

    public WorldMapRemotePlayer getOrCreatePlayer(IsoPlayer isoPlayer) {
        return this.getOrCreatePlayerByID(isoPlayer.OnlineID);
    }

    public WorldMapRemotePlayer getPlayerByID(short _short) {
        return (WorldMapRemotePlayer)this.playerLookup.get(_short);
    }

    public ArrayList<WorldMapRemotePlayer> getPlayers() {
        return this.playerList;
    }

    public void removePlayerByID(short _short) {
        this.playerList.removeIf(worldMapRemotePlayer -> worldMapRemotePlayer.getOnlineID() == _short);
        this.playerLookup.remove(_short);
    }

    public void Reset() {
        this.playerList.clear();
        this.playerLookup.clear();
    }
}
